package com.huawei.fastengine.fastview.download.utils;

import android.content.Context;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;

public abstract class PackageManagerUtils {
    private static final String TAG = "PkgManageUtils";
    private static int isSystemApp = -1;

    public static boolean checkPermission(Context context, String str) {
        FastViewLogUtils.d(TAG, "install checkPermission: start: ");
        int checkPermission = context.getPackageManager().checkPermission(str, context.getPackageName());
        if (checkPermission == 0) {
            return true;
        }
        FastViewLogUtils.e(TAG, "no this permission, result = " + checkPermission);
        return false;
    }

    public static boolean hasInstallPermission(Context context) {
        return checkPermission(context, "android.permission.INSTALL_PACKAGES");
    }

    public static boolean systemApp(Context context) {
        FastViewLogUtils.d(TAG, "install systemApp: " + isSystemApp);
        if (-1 == isSystemApp) {
            if (hasInstallPermission(context)) {
                isSystemApp = 1;
            } else {
                isSystemApp = 0;
            }
        }
        return isSystemApp == 1;
    }
}
